package com.netcracker.util.service;

import com.netcracker.db.exception.DBException;
import com.netcracker.entity.Language;
import com.netcracker.util.dao.DAOFacade;
import com.netcracker.util.service.exception.DataTransmittingException;
import com.netcracker.util.service.exception.NullDataException;
import java.util.List;

public class LanguageService {
    
    private DAOFacade daoFacade;
    
    public LanguageService(DAOFacade daoFacade) {
        this.daoFacade = daoFacade;
    }
    
    public void setDAOFacade(DAOFacade daoFacade) {
        this.daoFacade = daoFacade;
    }
    
    public List<Language> getAllLanguages() throws DataTransmittingException, NullDataException {
        try {
            List<Language> languages = daoFacade.getLanguageDAO().findAll();
            if (languages == null) 
                throw new NullDataException("There are no languages.");
            return languages;
        } catch(DBException ex) {
            throw new DataTransmittingException(ex.getMessage(), ex);
        }
    }
    
}
